#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 @Author: Y-aong
 @FileName: datetime_utils.py
 @DateTime: 2024/6/5 20:29
 @Version : 3.10
 @Description: 日期工具类
"""
import datetime


def calculate_time_difference(end_time, start_time):
    """计算并返回两个时间字符串之间的时间差，格式为HH:MM:SS。"""
    # 计算时间差
    if end_time is None:
        end_time = datetime.datetime.now()
    if start_time is None:
        start_time = datetime.datetime.now()
    time_diff = end_time - start_time
    # 将时间差转换为总秒数，然后格式化为HH:MM:SS
    hours, remainder = divmod(time_diff.seconds, 3600)
    minutes, seconds = divmod(remainder, 60)
    # 格式化输出
    return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
